<?php
namespace App\Admin;
class haha{
public $appkey="06caf93bb3fbc855c5566a1449cc7f17";
public $url;
public $params;
public $content;
public $paramstring;
public $result;
//************1.按更新时间查询笑话************
public function getRequest1(){
    $this->url = "http://japi.juhe.cn/joke/content/list.from";
    $this->params = array(
        "sort" => "asc",//类型，desc:指定时间之前发布的，asc:指定时间之后发布的
        "page" => "",//当前页数,默认1
        "pagesize" => "1",//每次返回条数,默认1,最大20
        "time" => "1418816972",//时间戳（10位），如：1418816972
        "key" => $this->appkey,//您申请的key
    );
$this->paramstring = http_build_query($this->params);
$this->content = $this::juhecurl($this->url,$this->paramstring);
    return $this-> content;
$this->result = json_decode($this->content,true);
if($this->result){
    if($this->result['error_code']=='0'){
        return $this-> result;
    }else{
        echo $this->result['error_code'].":".$this->result['reason'];
    }
}else{
    echo "请求失败";
}
}

//**************************************************
//************2.最新笑话************
public function getRequest2(){
    $this->url = "http://japi.juhe.cn/joke/content/text.from";
    $this->params = array(
        "page" => "",//当前页数,默认1
        "pagesize" => "",//每次返回条数,默认1,最大20
        "key" => $this->appkey,//您申请的key
    );
    $this->paramstring = http_build_query($this->params);
    $this->content = $this::juhecurl($this->url,$this->paramstring);
    $this->result=$this->content;
//    $this->result = json_decode($this->content,true);
    if($this->result){
        if($this->result['error_code']=='0'){
            print_r($this->result);
        }else{
            echo $this->result['error_code'].":".$this->result['reason'];
        }
    }else{
        echo "请求失败";
    }
}

//**************************************************

//************3.按更新时间查询趣图************
public function getRequest3(){
    $this->url = "http://japi.juhe.cn/joke/img/list.from";
    $this->params = array(
        "sort" => "",//类型，desc:指定时间之前发布的，asc:指定时间之后发布的
        "page" => "",//当前页数,默认1
        "pagesize" => "",//每次返回条数,默认1,最大20
        "time" => "",//时间戳（10位），如：1418816972
        "key" => $this->appkey,//您申请的key
    );
    $this->paramstring = http_build_query($this->params);
    $this->content = $this::juhecurl($this->url,$this->paramstring);
    $this->result = json_decode($this->content,true);
    if($this->result){
        if($this->result['error_code']=='0'){
            print_r($this->result);
        }else{
            echo $this->result['error_code'].":".$this->result['reason'];
        }
    }else{
        echo "请求失败";
    }
}

//**************************************************




//************4.最新趣图************
public function getRequest4(){
    $this->url = "http://japi.juhe.cn/joke/img/text.from";
    $this->params = array(
        "page" => "",//当前页数,默认1
        "pagesize" => "",//每次返回条数,默认1,最大20
        "key" => $this->appkey,//您申请的key
    );
    $this->paramstring = http_build_query($this->params);
    $this->content = $this::juhecurl($this->url,$this->paramstring);
    $this->result = json_decode($this->content,true);
    if($this->result){
        if($this->result['error_code']=='0'){
            print_r($this->result);
        }else{
            echo $this->result['error_code'].":".$this->result['reason'];
        }
    }else{
        echo "请求失败";
    }
}

//**************************************************
    function juhecurl($url,$params=false,$ispost=0){
        $httpInfo = array();
        $ch = curl_init();

        curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
        curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );
        curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
        curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
        curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
        if( $ispost )
        {
            curl_setopt( $ch , CURLOPT_POST , true );
            curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
            curl_setopt( $ch , CURLOPT_URL , $url );
        }
        else
        {
            if($params){
                curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
            }else{
                curl_setopt( $ch , CURLOPT_URL , $url);
            }
        }
        $response = curl_exec( $ch );
        if ($response === FALSE) {
            //echo "cURL Error: " . curl_error($ch);
            return false;
        }
        $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
        $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
        curl_close( $ch );
        return $response;
    }
}